<script setup>
import useTable from "@/utils/useTable";
import {http} from "@/api";
import { getStatus } from "@/utils/common";
import { ref } from "vue";
/**
 * 表格
 * @type {Ref<UnwrapRef<*[]>>}
 */
const {
  searchParams,
  pageNo,
  pageSize,
  total,
  changePage,
  changeSize,
  dataSource,
  search,
  reset,
  openAdd,
  openEdit,
  openDelete
} = useTable({
  requestFn: http.ProductOrder,
  routerPre: 'ProductOrder',
  format: (data) => {
    return data.map(item => {
      return {
        ...item,
        goods: item.goods || {}
      }
    })
  },
  params: {
    index: '0',
    name: '',
  }
})
const handleClick = (tab, event) => {
  search()
}
</script>


<template>
  <PageMain title="商品订单">
    <el-tabs v-model="searchParams.index" @tab-change="handleClick">
      <el-tab-pane label="全部" name="0"></el-tab-pane>
      <el-tab-pane label="待发货" name="1"></el-tab-pane>
      <el-tab-pane label="待处理退货" name="3"></el-tab-pane>
    </el-tabs>
    <el-form label-suffix="：" inline>
      <el-form-item label="订单号">
        <el-input v-model="searchParams.order_no" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="table-box">
      <el-table :data="dataSource">
        <el-table-column label="订单号" prop="order_no">
        </el-table-column>
        <el-table-column label="状态">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              {{ getStatus(scope.row) }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="create_time">
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button type="text" @click="openEdit(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          v-model:current-page="pageNo"
          v-model:page-size="pageSize"
          :page-sizes="[10, 50, 100, 200]"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="changeSize"
          @current-change="changePage"
      />
    </div>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
